<?php 
include_once("inc/connection.php");
include_once("inc/constants.inc.php");
session_start();

$student_id = $_SESSION['userID'];
$aptitudeTestOver = false;
$technicalTestOver = false;
if(!isset($_SESSION['login']) || empty($_SESSION['login']) || !isset($_SESSION['email']) || empty($_SESSION['email']))
{
	header("Location: login.php?error=session-timeout");
}
if(isset($_GET['test_type']) && !empty($_GET['test_type']) && ($_GET['test_type']==1 || $_GET['test_type']==2))
{
	$test_type = $_GET['test_type'];

}
else
	header("Location: test.php?error=invalid-access");

	
	$res = mysql_query("SELECT * FROM `answer_sheet` where `studentID` = $_SESSION[userID] and  `isReset`='no' ");	
	while($row = mysql_fetch_array($res))
	{
	$res1 = mysql_query("SELECT * FROM `question_type`");	
	while($row1 = mysql_fetch_array($res1))
	{
		if(isset($row['typeId']) && $row['typeId']==$row1['QTypeid'])
		{
			header("Location: test.php?error=invalid-access");
			exit(0);
		}
		
	}
	}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>Smartek online test | Test</title>
		<link rel="SHORTCUT ICON" href="img/disp/favicon.png" />	
		<link rel="stylesheet" href="css/bootstrap.css"  type="text/css"/>

	</head>
	<body>
		<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
		<script src="js/bootstrap.js"></script>
		<script src="js/jquery.timer.js"></script>
		<script src="js/timerfunction.js"></script>
		<script type="text/javascript">	
			function confirm_popup(msg){
				$('#confirm_popup').removeClass("hide"); 
				$("#confirm_popup").show();
				$("#confirm_popup").css('top',$(window).scrollTop()+200);
				$('#confirm_content').html(msg);
				$('#confirm_no').click(function(){
						 $("#confirm_popup").hide();
						return false;
				});
				$('#confirm_yes').click(function(){
					document.getElementById("answer-sheet").submit();
				});   
			}

			 $(function(){				 
				 $.get( "ajax/get_exam_time.php?typeId="+<?php echo $test_type; ?>+"&student_id="+<?php echo $student_id; ?>, function( data ) {
					startTimer(data, "#answer-sheet");
				});
			});
			
			$(function(){
				 $("#showTimer").hide();
			});
			
			$(document).ready(function(){
				  $("#hideTimer").click(function(){
					$("#countdown-wrapper").hide();
					$("#hideTimer").hide();
					$("#showTimer").show();
				  });
				  $("#showTimer").click(function(){
					$("#countdown-wrapper").show();
					$("#showTimer").hide();
					$("#hideTimer").show();
				  });
			});
		</script>
		<div class="container">
			<img src="img/disp/logo.png" alt="">
		</div>
		
		
		<div class="container">
			<hr class="featurette-divider">
		</div>


		<div id="confirm_popup" class="hide">
			<div id="confirm_content"></div>
			<br/><br/>
			<input id='confirm_yes' type='button' class="btn btn-default" value='Yes' />
			<input id='confirm_no' type='button' class="btn btn-primary" value='No' />
		</div>		
		<div class="container">
			<div class="row">
				<div class="span12" > <!--pagination-centered-->
					<form method="post" id="answer-sheet" action="process/submit-answer.php">						
						<h5>Instructions:</h5>
						<div id="countdown-wrapper">Time remaining&nbsp;&nbsp;
							<span id="countdown"></span>							
						</div>
						<div class="container" style="position:fixed;">
							<div class="row pull-right">
								<div class="span4 pull-right" >
									<div class="pull-right">
										<input type="button" id="hideTimer" class="btn" value="Hide Timer"/>
										<input type="button" id="showTimer" class="btn" value="Show Timer"/>
									</div>
								</div>
							</div>
						</div>


						<?php if(isset($instruction)) echo $instruction; ?>
						</br></br>
						<?php
							$result = mysql_query("SELECT * FROM question_table WHERE typeId=$test_type");	
								$question_number = 0;
								while($row = mysql_fetch_array($result))
								{	
								$question_number++;
						?>
								<div class="container">
									<div class="row">
										<div class="span12">
										<?php echo "</br>".$question_number.". ".$row['question']."</br>"; ?>
										</div>
										<div class="span11 choices">
											<input type="radio" name="<?php echo $question_number; ?>"  value="<?php echo $question_number."_".$row['questionNumber']."_a"; ?>"> <?php echo $row['optionOne']."</br>";  ?>
											<input type="radio" name="<?php echo $question_number; ?>"  value="<?php echo $question_number."_".$row['questionNumber']."_b"; ?>"> <?php echo $row['optionTwo']."</br>";  ?>
											<input type="radio" name="<?php echo $question_number; ?>"  value="<?php echo $question_number."_".$row['questionNumber']."_c"; ?>"> <?php echo $row['optionThree']."</br>";  ?>
											<input type="radio" name="<?php echo $question_number; ?>"  value="<?php echo $question_number."_".$row['questionNumber']."_d"; ?>"> <?php echo $row['optionFour']."</br>";  ?>
										</div>										
									</div>
								</div>	
						<?php		
								}
								
						?>	
						</br></br>
						<input type="hidden" name="duration" value="60" />
						<input type="hidden" name="test_type" value="<?php echo $test_type; ?>" />
					   <input type="button" class="btn" name="button" value="Submit" onclick="confirm_popup('Do you really want to submit the answer sheet?')" />
					</form>
				</div>
			</div>
		</div>
		</br>
		<div class="container">
			<hr class="featurette-divider">
		</div>
		<div class="container marketing">
      <!-- FOOTER -->
      <footer>
        <p>&copy; 2014 SCS &middot; </p>
      </footer>

    </div><!-- /.container -->
	</body>
</html>